﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace davejk.Minecraft.ServerWrapper.Utils
{
    public partial class SaveWorldAs : Form
    {
        public SaveWorldAs(string worldname)
        {
            InitializeComponent();

            _SaveChoice = String.Empty;
            Save.Enabled = false;

            LSaveAsHint.Text = String.Format(LSaveAsHint.Text, worldname);
        }

        private void StartSaveCopy(object sender, EventArgs e)
        {
            if (Directory.Exists(Utils.SetupHelper.AppBaseDirectory + "\\Minecraft\\" + SaveAs.Text))
            {
                MessageBox.Show("The world '" + SaveAs.Text + "' already exists.");
                //todo: overwrite support
            }
            else
            {
                _SaveChoice = SaveAs.Text;
                this.DialogResult = System.Windows.Forms.DialogResult.Yes;
                this.Close();
            }
        }

        private string _SaveChoice;
        public string SaveChoice {
            get {
                return _SaveChoice;
            }
        }

        private void Cancelled(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SaveAsChanged(object sender, EventArgs e)
        {
            Save.Enabled = !string.IsNullOrEmpty(SaveAs.Text);
        }
    }
}
